package com.hd.trans.utils;

import android.os.SystemClock;
import android.view.View;

public class ViewClickUtil {

    private static final long DEFAULT_INTERVAL = 500;
    private static long mAllowClickTime;

    public static boolean doubleClick(View view, long interval) {
        long currentMillis = SystemClock.uptimeMillis();
        Object obj = view.getTag(view.getId());
        if (obj != null && currentMillis <= (long) obj) {//如果当前时间小于允许点击的时间则禁止点击
            return true;
        } else {
            view.setTag(view.getId(), currentMillis + interval);//允许点击的时间=点击时间+interval
            return false;
        }
    }

    public static boolean doubleClick(View view) {
        long currentMillis = SystemClock.uptimeMillis();
        if (currentMillis <= mAllowClickTime) {//如果当前时间小于允许点击的时间则禁止点击
            return true;
        } else {
            mAllowClickTime = currentMillis + DEFAULT_INTERVAL;//允许点击的时间=点击时间+500毫秒
            return false;
        }
    }
}
